package com.yuke.cloud.service.uac.enums;

import com.google.common.collect.Lists;
import com.yuke.cloud.common.base.constant.GlobalConstant;
import com.yuke.cloud.common.base.enums.ErrorCodeEnum;
import com.yuke.cloud.common.base.exception.BusinessException;
import org.springframework.util.StringUtils;

import java.util.Arrays;
import java.util.List;

import static com.yuke.cloud.common.base.constant.GlobalConstant.ValidateTypeEnum.*;


/**
 * The enum Uac email template enum.
 *
 * @author
 */
public enum UacSmsTemplateEnum {

	/**
	 * App更新
	 */
	UAC_SMS_APP_NEW_VERSION(APP_NEW_VERSION, "SMS_147715048", "App更新"),
	/**
	 * 新产品上线
	 */
	UAC_SMS_APP_NEW_PRODUCT(APP_NEW_PRODUCT, "SMS_147715047", "新产品上线"),
	/**
	 * 促销活动
	 */
	UAC_SMS_APP_NEW_PROMOTE(APP_NEW_PROMOTE, "SMS_147715046", "促销活动");

	/**
	 * The Key.
	 */
	private GlobalConstant.ValidateTypeEnum  key;
	/**
	 * The Subject.
	 */
	private String templateCode;
	/**
	 * The Location.
	 */
	private String description;

	UacSmsTemplateEnum(GlobalConstant.ValidateTypeEnum key, String templateCode, String description) {
		this.key = key;
		this.templateCode = templateCode;
		this.description = description;
	}

	/**
	 * 获取List集合
	 *
	 * @return List list
	 */
	public static List<UacSmsTemplateEnum> getList() {
		return Arrays.asList(UacSmsTemplateEnum.values());
	}
	/**
	 * 根据key获取该对象
	 *
	 * @param key key
	 *
	 * @return this enum
	 */
	public static UacSmsTemplateEnum getEnum(GlobalConstant.ValidateTypeEnum  key) {
		for (UacSmsTemplateEnum ele : UacSmsTemplateEnum.values()) {
			if (key.equals(ele.getKey())) {
				return ele;
			}
		}
		return null;
	}
	/**
	 * 根据key获取该对象
	 *
	 * @param templateCode templateCode
	 *
	 * @return this enum
	 */
	public static UacSmsTemplateEnum getEnum(String templateCode) {
		UacSmsTemplateEnum uacSmsTemplateEnum = null;
		for (UacSmsTemplateEnum ele : UacSmsTemplateEnum.values()) {
			if (templateCode.equals(ele.getTemplateCode())) {
				uacSmsTemplateEnum = ele;
				break;
			}
		}
		return uacSmsTemplateEnum;
	}

	public static boolean isSmsTemplate(String smsTemplateCode) {

		if (StringUtils.isEmpty(smsTemplateCode)) {
			throw new BusinessException(ErrorCodeEnum.UAC10011020);
		}
		List<String> templetCodeList = getTemplateCodeList();

		return templetCodeList.contains(smsTemplateCode);
	}


	public static List<String> getTemplateCodeList() {
		List<String> templetCodeList = Lists.newArrayList();
		List<UacSmsTemplateEnum> list = getList();
		for (UacSmsTemplateEnum templetEnum : list) {
			if (StringUtils.isEmpty(templetEnum.getTemplateCode())) {
				continue;
			}
			templetCodeList.add(templetEnum.getTemplateCode());
		}
		return templetCodeList;
	}
	/**
	 * Gets key.
	 *
	 * @return the key
	 */
	public GlobalConstant.ValidateTypeEnum getKey() {
		return key;
	}

	/**
	 * Gets location.
	 *
	 * @return the location
	 */
	public String getDescription() {
		return description;
	}

	/**
	 * Gets subject.
	 *
	 * @return the subject
	 */
	public String getTemplateCode() {
		return templateCode;
	}

}
